package com.codeoss.framework.webide.app.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.util.StringUtils;
import com.codeoss.module.ir.model.IrApplication;

public class CommonAppDataHandler implements IAppDataHandler {

	@Override
	public void dataExport(YunContext yunContext, IrApplication irApplication, String tableName)
			throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void dataImport(YunContext yunContext, IrApplication irApplication, String tableName,List<String> filenameList)
			throws IOException {
		// TODO Auto-generated method stub

	}

	protected List<String> getModuleTypeList(YunContext yunContext, IrApplication irApplication){
		List<String> moduleTypeList=new ArrayList<String>();
		String sModuleType=irApplication.getModuleTypeList();
		if(!StringUtils.isEmpty(sModuleType)) {
			String moduleTypeArray[]=sModuleType.split(",");
			for (int i = 0; i < moduleTypeArray.length; i++) {
				moduleTypeList.add(moduleTypeArray[i]);
			}
		}
		return moduleTypeList;
	}
	
	protected void writeConfigKeyValue(YunContext yunContext,String key,String value) {
		PrintWriter pw=(PrintWriter)yunContext.getAttribute("__pw__");
		pw.println(key+"="+value);
	}
	
	protected FileOutputStream createFileOutputStream(YunContext yunContext,String filename)throws IOException {
		File folder=(File)yunContext.getAttribute("__folder__");
		FileOutputStream fos = new FileOutputStream(
				new File(folder + File.separator + filename + ".properties"));
	    return fos;
	}
	
	protected FileInputStream createFileInputStream(YunContext yunContext,String filename)throws IOException {
		File folder=(File)yunContext.getAttribute("__folder__");
		FileInputStream fis = new FileInputStream(
				new File(folder + File.separator + filename + ".properties"));
	    return fis;
	}
}
